<%@page import="cn.jhc.dao.TitleDAO"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="cn.jhc.dao.ConnectionFactory"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/houtai.css"></link>
<title>乐谱信息</title>
</head>
<script type="text/javascript">
	function MM_popupMsg(msg) {
		alert(msg);
	}
</script>
<body>
	<%
		int CurrentPage = 1;
		int intPageCount;
		if (request.getParameter("page") != null)
			CurrentPage = Integer.parseInt(request.getParameter("page"));
		if (CurrentPage < 1)
			CurrentPage = 1;
		int titleCount = 4;
	%>
	<%
		String search = request.getParameter("search");
		TitleDAO dao = new TitleDAO();
		dao.setCon(ConnectionFactory.getConnection());
		intPageCount = dao.getMusicCount(titleCount);
		if(intPageCount==0){
			CurrentPage=1;
			intPageCount=1;
		}else{
		if (CurrentPage > intPageCount)
			CurrentPage = intPageCount;
		}
	%>
	<div id="wrapper">
		<jsp:include page="./houtai_header.jsp"></jsp:include>
		<div id="left">
			<div class="button2"><a href="houtai_deleteyuepu.jsp?search=no">乐谱信息</a></div>
		</div>
		<div id="right">
			<div id="right_top">
				<div id="addresstext"><a>所在位置： 乐谱信息</a></div>
				<div id="sousuo2">
					<form method="post" action="./houtai_searchMusic.do">
						<input type="text" name="title" id="title" size="21"
						value="请输入曲谱" />
						<input type="submit" value="搜索曲谱"></input>
					</form>
				</div>
			</div>
			<%if(search.equals("no")){%>
			<div align="center">
				<table width="100%">
					<%
						Connection conn = null;
						conn = ConnectionFactory.getConnection();
						Statement stmt = conn.createStatement();
						ResultSet rs = stmt
								.executeQuery("select id ,imagename,musicname,title,content,integral from uploadfile order by id desc limit "
										+ (CurrentPage-1) * (titleCount) + "," + titleCount + "");
					%>
					<tr>
						<th height="25" width="180">乐谱名称</th>
						<th width="68%">歌曲简介</th>
						<th>积分</th>
						<th width="50">操作</th>
					</tr>
					<%
						while (rs.next()) {
					%>
					<tr>
						<td height="25"><div align="center"><%=rs.getString(4)%></div></td>
						<td><div id="music-jianjie" align="left"><%=rs.getString(5)%></div></td>
						<td>
							<div align="center">
								<form method="post" action="./houtai_updateNeedIntegral.do">
									<input type="text" name="integral" size="3" value="<%=rs.getInt(6)%>"/>
									<input type="hidden" name="id" value="<%=rs.getInt(1)%>">
									<input type="submit" value="更改"  onclick="MM_popupMsg('更改成功！')"></input>
								</form>
							</div>
						</td>
						<td><div align="center"><a href="houtaideleteyuepu.do?id=<%=rs.getInt(1)%>">删除</a></div></td>
					</tr>
					<%
						}
						conn.close();
					%>
				</table>
				<div align="right">
					<a>第<%=CurrentPage%>页 共<%=intPageCount%>页
					</a> <a href="houtai_deleteyuepu.jsp?page=<%=1%>&search=no">首页</a>
					<%
						if (CurrentPage > 1) {
					%>
					<a href="houtai_deleteyuepu.jsp?page=<%=CurrentPage - 1%>&search=no">上一页</a>
					<%
						} else {
					%>
					上一页
					<%
						}
					%>
					<%
						if (CurrentPage >= intPageCount) {
					%>
					下一页
					<%
						} else {
					%>
					<a href="houtai_deleteyuepu.jsp?page=<%=CurrentPage + 1%>&search=no">下一页</a>
					<%
						}
					%>
					<a href="houtai_deleteyuepu.jsp?page=<%=intPageCount%>&search=no">末页</a>
				</div>
			</div>
			<%}else if(search.equals("yes")){ %>
			<div align="center">
				<table width="100%">
					<tr>
						<th height="25" width="180">乐谱名称</th>
						<th width="68%">歌曲简介</th>
						<th>积分</th>
						<th width="50">操作</th>
					</tr>
					<c:forEach items="${requestScope.Music}" var="mus" >
					<tr>
						<td height="25"><div align="center">${mus.title}</div></td>
						<td><div id="music-jianjie" align="left">${mus.content}</div></td>
						<td>
							<div align="center">
								<form method="post" action="./houtai_updateNeedIntegral.do">
									<input type="text" name="integral" size="3" value="${mus.integral}"/>
									<input type="hidden" name="id" value="${mus.id}">
									<input type="submit" value="更改"  onclick="MM_popupMsg('更改成功！')"></input>
								</form>
							</div>
						</td>
						<td><div align="center"><a href="houtaideleteyuepu.do?id=${mus.id}">删除</a></div></td>
					</tr>
					</c:forEach>
				</table>
			</div>
			<div align="center">
				<form method="post" action="./houtai_deleteyuepu.jsp?search=no">
					<input type="submit" value="返回"></input>
				</form>
			</div>
			<%} %>
		</div>
	</div>
</body>
</html>